<template>
  <div class="add-super-user-container">
    <el-form ref="superUserRef" :model="superUserForm" :rules="superUserRule" label-position="left" label-width="80px">
      <el-form-item label="用户名" prop="username">
        <el-input v-model="superUserForm.username" autocomplete="off" />
      </el-form-item>
      <el-form-item label="昵称" prop="nickname">
        <el-input v-model="superUserForm.nickname" autocomplete="off" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="resetForm('superUserRef')">重 置</el-button>
      <el-button type="primary" @click="saveSuperUser">确 定</el-button>
    </div>
  </div>
</template>

<script>
import { addSuperUser } from '@/api/super_user'
export default {
  name: 'AddSuperUser',
  components: {},
  props: {},
  data () {
    return {
      superUserForm: {
        username: '',
        nickname: ''
      },
      superUserRule: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 2, max: 15, message: '长度在 2 到 15 个字符', trigger: 'blur' }
        ],
        nickname: [
          { required: true, message: '请输入用户昵称', trigger: 'blur' },
          { min: 2, max: 15, message: '长度在 2 到 15 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
    saveSuperUser: async function () {
      const res = await addSuperUser(this.superUserForm)
      if (res) {
        this.$message({ message: '添加成功', type: 'success', duration: 1000 })
        this.$emit('reset-super-users')
      }
    },
    resetForm(refName) {
      this.$refs[refName].resetFields()
    }
  }
}
</script>

<style scoped lang="scss"></style>
